package com.atguigu.zhxy.controller;

import com.atguigu.zhxy.pojo.Teacher;
import com.atguigu.zhxy.service.TeacherService;
import com.atguigu.zhxy.util.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Api(tags = "教师控制器")
@RestController
@RequestMapping("/sms/teacherController")
public class TeacherController {
    @Autowired
    private TeacherService teacherService ;

    @ApiOperation("获取所有教师")
    @GetMapping("/getTeachers/{pageNum}/{pageSize}")
    public Result getTeachers(
            @ApiParam("分页查询的页码数")@PathVariable("pageNum") Integer pageNum,
            @ApiParam("分页查询的记录数")@PathVariable("pageSize") Integer pageSize,
            @ApiParam("查询条件") Teacher teacher
    ){
        //        分页带条件查询
        Page<Teacher> page = new Page<>(pageNum, pageSize);
//        通过服务层
        IPage<Teacher> gradeIPage = teacherService.getGradesByPN(page,teacher);
//        封装result对象并返回
        return Result.ok(gradeIPage) ;
    }

    @ApiOperation("更新或修改教师")
    @PostMapping("/saveOrUpdateTeacher")
    public Result saveOrUpdateTeacher(@RequestBody Teacher teacher){
        teacherService.saveOrUpdate(teacher) ;
        return Result.ok() ;
    }

    @ApiOperation("根据教师id数组删除")
    @DeleteMapping("/deleteTeacher")
    public Result deleteTeacher(@RequestBody List<Integer> idList){
        teacherService.removeByIds(idList) ;
        return Result.ok() ;
    }
}
